Fix access to QByteArray/QString outside the valid range. (#537)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Tue, 14 Apr 2020 21:33:19 +0000 (15:33 -0600)
committerGitHub <noreply@github.com>
Tue, 14 Apr 2020 21:33:19 +0000 (15:33 -0600)
With Qt 5.15, and likely 5.14, the following warnings were generated during
testo:
Using QByteRef with an index pointing outside the valid range of a QByteArray. The corresponding behavior is deprecated, and will be changed in a future version of Qt.
Using QCharRef with an index pointing outside the valid range of a QString. The corresponding behavior is deprecated, and will be changed in a future version of Qt.
Note this requires Qt to be compiled for debug.

These warnings can be debugged by running testo with
"export QT_FATAL_WARNINGS=1" to generate core dumps.

I suspect the appending of null terminators in ggv_bin is unecessary,
i.e. I beleive QByteArray::resize() in ggv_bin_read_bytes will take
care of this.  Never the less I slavishly kept adding them just to make
certain.

ggv_bin.cc
xcsv.cc

index 550bee5ef0e871f44ea70f93fdc0ac7819021d00..40b0b18c3bec66492051fe65b2a4bfad08c7d7d8 100644 (file)
@@ -84,7 +84,7 @@ GgvBinFormat::ggv_bin_read_text16(QDataStream& stream, QByteArray& buf, const ch
 {
   quint16 len = ggv_bin_read16(stream, descr);
   ggv_bin_read_bytes(stream, buf, len, descr);
-  buf[len] = 0;
+  buf.append('\0');
   if (global_opts.debug_level > 1) {
     qDebug() << "ovl: text =" << QString::fromLatin1(buf.constData()).simplified();
   }
@@ -102,7 +102,7 @@ GgvBinFormat::ggv_bin_read_text32(QDataStream& stream, QByteArray& buf, const ch
     fatal(MYNAME ": Read error, max len exceeded (%s)\n", descr ? descr : "");
   }
   ggv_bin_read_bytes(stream, buf, len, descr);
-  buf[len] = 0;
+  buf.append('\0');
   if (global_opts.debug_level > 1) {
     qDebug() << "ovl: text =" << QString::fromLatin1(buf.constData()).simplified();
   }
@@ -490,7 +490,7 @@ GgvBinFormat::read()
 
   QByteArray buf;
   ggv_bin_read_bytes(stream, buf, 0x17, "magic");
-  buf[23] = 0;
+  buf.append('\0');
   if (global_opts.debug_level > 1) {
     qDebug() << "ovl: header =" << buf.constData();
   }
diff --git a/xcsv.cc b/xcsv.cc
index 61ce7bc41569417cc4de08f9cddbef08ae373c23..4fffd7b9fcbf68b43922d2da41c6e5d336d1ab44 100644 (file)
--- a/xcsv.cc
+++ b/xcsv.cc
@@ -983,8 +983,6 @@ XcsvFormat::xcsv_waypt_pr(const Waypoint* wpt)
   double utme, utmn;
   char utmzc;
 
-  buff[0] = '\0';
-
   if (oldlon < 900) {
     pathdist += radtomiles(gcdist(RAD(oldlat),RAD(oldlon),
                                   RAD(wpt->latitude),RAD(wpt->longitude)));